#include "PluginOsg.h"

#include <QMdiSubWindow>
#include <QLabel>
#include <EDesignerCore.h>
#include <ActionManager.h>

#include <QMetaProperty>
#include <iostream>
#include <InteractionWithUIFunctions.h>
#include <EngineFunctions.h>
#include <SceneViewerFunctions.h>
#include <SceneViewer.h>
#include <OsgClassDataSource/NodeOsg.h>
#include <CallBackTest.h>
#include <NodeInfoContainer.h>
#include <VisitorChangeSimState.h>
PluginOsg::PluginOsg()
{
    //m_objectInspectorModel = new ObjectInspectorModelOsg;
    m_directorOsg = QSharedPointer<ObjectInspectorDirectorOsg>(new ObjectInspectorDirectorOsg);
    m_simObjOsg = QSharedPointer<SimulationObjectOsg>(new SimulationObjectOsg);
    m_mdiArea = new QMdiArea;
    m_fileObjOsg = QSharedPointer<FileSystemObjectOsg>(new FileSystemObjectOsg);
    m_factoryObjOsg = QSharedPointer<ClassFactoryObjectOsg>(new ClassFactoryObjectOsg);


    //osg���س�ʼ������
	SceneViewerFunctions::addDefaultTrackBallCameraManipulator("default track ball camera manipulator");
    SceneViewerFunctions::addCameraManipulatorIntersection("Intersection");

    SceneViewerFunctions::setUpViewInWindow(10,20,800,600);
    SceneViewerFunctions::addCoordinateToSceneViewer();

    //osg::ref_ptr<OsgHudContainer> hud_container = new OsgHudContainer();
    //SceneViewerFunctions::addOsgNodeToSceneViewer(hud_container);
    //SceneViewer::instance()->getViewer()->addEventHandler(new OsgPickHandler());

    SceneViewerFunctions::setUpSceneData();
    SceneViewer::instance()->setUpdateVisitorMask(0x2);
    VisitorChangeSimState simStateVisitor;simStateVisitor.setEnableCallBack(false);
    SceneViewer::instance()->getModelRoot()->accept(simStateVisitor);

    SceneViewer::instance()->getViewer()->getCamera()->setCullMask(0x4);
    //SceneViewer::instance()->getModelRoot()->setUpdateCallback(new CallBackTest);
}


QString PluginOsg::name()
{
    return QString("PluginOsg");
}

EDesignerCustomPlugin::PluginType PluginOsg::pluginType()
{
	return EDesignerCustomPlugin::PluginType::UI_OBJECT_INSPECTOR;
}


QSharedPointer<ObjectInspectorDirector> PluginOsg::getObjectInspectorDirector()
{
    return m_directorOsg;
    //return EDesignerCustomPlugin::getObjectInspectorDirector();
}

QMdiArea* PluginOsg::getMainWindowMdiArea()
{
	QMdiSubWindow* sub_window = m_mdiArea->addSubWindow(InteractionWithUIFunctions::getSceneViewerWidget());
	
    //EngineFunctions::start();
	sub_window->showMaximized();

	return m_mdiArea;
}

void PluginOsg::setUpActions()
{

}

void PluginOsg::pluginLoaded()
{

}


QSharedPointer<SimulationObject> PluginOsg::getSimulationObject()
{
    return m_simObjOsg;
}

QSharedPointer<FileSystemObject> PluginOsg::getFileSystemObject()
{
    return m_fileObjOsg;
    //return EDesignerCustomPlugin::getFileSystemObject();

}

QSharedPointer<ClassFactoryObject> PluginOsg::getClassFactoryObject()
{
    return m_factoryObjOsg;
}

Q_EXPORT_PLUGIN2(EDesignerCustomPlugin, PluginOsg);
